﻿using UnityEngine;
namespace LitTools
{
    /// <summary>
    /// 引导位置基类
    /// </summary>
    public abstract class TutorialPosition
    {
        public Vector3 offset;

        public Vector3 GetPosition()
        {
            var defaultScale = 1920f / 1080;
            var realScale = (float)Screen.height / Screen.width;
            var scale = defaultScale / realScale;
            var result = offset;
            result.y *= scale;

            return GetPosition() + result;
        }

        protected abstract Vector3 GetWorldPosition();
    }

    /// <summary>
    /// 指定位置
    /// </summary>
    public class TutorialPosition_Position : TutorialPosition
    {
        public Vector3 position;

        public TutorialPosition_Position(Vector3 position)
        {
            this.position = position;
        }

        public TutorialPosition_Position(Vector3 position, Vector3 offset)
        {
            this.position = position;
            this.offset = offset;
        }

        protected override Vector3 GetWorldPosition()
        {
            return position;
        }
    }

    /// <summary>
    /// 通过物体名字获取位置
    /// </summary>
    public class TutorialPosition_GameObjectName : TutorialPosition
    {
        private string goName;
        public TutorialPosition_GameObjectName(string name)
        {
            goName = name;
        }

        public TutorialPosition_GameObjectName(string name, Vector2 offset)
        {
            goName = name;
            this.offset = offset;
        }

        protected override Vector3 GetWorldPosition()
        {
            GameObject go = GameObject.Find(goName);
            if (go == null)
            {
                Debug.LogError($"[TutorialPosition] 找不到名字为{goName}的物体");
                return Vector3.zero;
            }
            return go.transform.position;
        }
    }
}